package com.chmingx.JavaBasic.basic;

import java.util.Arrays;

public class Demo{
    public static void main(String[] args){
        System.out.println(find(4));
    }

    public static int find(int target){
        int[] arr = {1, 3, 5, 7, 9, 11};
        int min = 0;
        int max = arr.length - 1;
        int mid;
        while (max >= min) {
            mid = (min + max) / 2;
            if (arr[mid] == target) {
                return mid;
            } else if (arr[mid] > target) {
                max = mid-1;
            } else {
                min = mid+1;
            }
        }
        return -1;
    }
}

class Singleton{
    private volatile static Singleton instance;

    private Singleton (){

    }

    public static Singleton getInstance(){
        if (instance == null){
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}

class Bubble{
    public static void main(String[] args){
        int[] arr = {1,6,3,2,9};
        for (int i = 0; i < arr.length - 1; i++){
            for (int j = i+1; j < arr.length; j++){
                if (arr[i] > arr[j]){
                    int tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
        for (int n: arr){
            System.out.println(n);
        }
    }
}

class ArrayDemo {
    public static void main(String[] args){
        int[] arr = {1, 3, 5, 7, 9};
        int index = 2;
        int value = 4;

        int[] arr2 = new int[arr.length + 1];
        for (int i = 0; i < index; i++){
            arr2[i] = arr[i];
        }
        for (int j = arr2.length - 1; j > index; j--){
            arr2[j] = arr[j-1];
        }
        arr2[index] = value;
        System.out.println(Arrays.toString(arr2));

        delete(2);
    }

    public static void delete(int index){
        int[] arr = {1, 3, 5, 7, 9, 11};
        for (int i = index; i < arr.length - 1; i++){
            arr[i] = arr[i+1];
        }
        arr[arr.length-1]=0;
        System.out.println(Arrays.toString(arr));

    }
}

class Person {
    public static void run() {
        String.valueOf("test");
    }
}

class Student extends Person {
    public static void run(){
        System.out.println("student");
    }
}

class StudentDemo {
    public static void main(String[] args) {
        Student s = new Student();
        s.run();
    }
}